<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>部门管理页面</title>
</head>
<body>
<div class="hrms_dept_container">
    <!-- 导航栏-->
    <%@ include file="./commom/head.jsp"%>


    <!-- 中间部分（左侧栏+表格内容） -->
    <div class="hrms_dept_body">
        <!-- 左侧栏 -->
        <%@ include file="./commom/leftsidebar.jsp"%>

        <!-- 部门表格内容 -->
        <div class="dept_info col-sm-10">
<div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">员工新增</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal add_emp_form">
                <div class="form-group">
                        <label for="add_inputName" class="col-sm-2 control-label">账号</label>
                        <div class="col-sm-8">
                            <input type="text" name="empCode" class="form-control" id="add_inputName" placeholder="如：admin">
                            <span id="helpBlock_add_inputName" class="help-block"></span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="add_inputName" class="col-sm-2 control-label">姓名</label>
                        <div class="col-sm-8">
                            <input type="text" name="empName" class="form-control" id="add_inputName2" placeholder="如：张三">
                            <span id="helpBlock_add_inputName" class="help-block"></span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="add_inputEmail" class="col-sm-2 control-label">邮箱</label>
                        <div class="col-sm-8">
                            <input type="email" name="empEmail" class="form-control" id="add_inputEmail" placeholder="zs@qq.com">
                            <span id="helpBlock_add_inputEmail" class="help-block"></span>
                        </div>
                    </div>
                      <div class="form-group">
                        <label for="add_inputEmail" class="col-sm-2 control-label">密码</label>
                        <div class="col-sm-8">
                            <input type="text" name="empPassword" class="form-control" id="empPassword" placeholder="123456">
                            <span id="helpBlock_add_inputEmail" class="help-block"></span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">性别</label>
                        <div class="col-sm-8">
                            <label class="radio-inline">
                                <input type="radio" checked="checked" name="gender" id="add_inputGender1" value="1"> 男
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="gender" id="add_inputGender2" value="0"> 女
                            </label>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="add_department" class="col-sm-2 control-label">部门</label>
                        <div class="col-sm-8">
                            <div class="checkbox">
                                <select class="form-control" name="deptId" id="add_department">
                                   <%-- <option value="1">CEO</option>--%>
                                </select>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
            
                <button type="button" id="save" class="btn btn-primary emp_save_btn"  style="width:100px;">保存</button>
            </div>
        </div><!-- /.modal-content -->

        </div><!-- /.dept_info -->
    </div><!-- /.hrms_dept_body -->



</div><!-- /.hrms_dept_container -->

<script type="text/javascript">
$(function(){
	  $(".modal-content").one("click",function () {
          console.log("click");
        $.ajax({
            url:"/HRMS/user/deptname",
            type:"GET",
            success:function (result) {
            	console.log(result.list);
                    $.each(result.list, function () {
                        var optionEle = $("<option></option>").append(this.deptName).attr("value", this.deptId);
                        optionEle.appendTo("#add_department");
                    });
                
            }
        });
        $('.emp-add-modal').modal({
            backdrop:static,
            keyboard:true
        });
        });
	  
	  $("#add_inputName").change(function () {
	        var empCode = $("#add_inputName").val();
	        $.ajax({
	            url:"/HRMS/user/code",
	            type:"GET",
	            data:{"empCode":empCode},
	            success:function (result) {
	                if (result.code == 100){
	                    $("#add_inputName").parent().parent().removeClass("has-error");
	                    $("#add_inputName").parent().parent().addClass("has-success");
	                    $("#helpBlock_add_inputName").text("用户名可用！");
	                    $(".emp_save_btn").attr("btn_name_exists", "success");
	                }else {
	                    $("#add_inputName").parent().parent().removeClass("has-success");
	                    $("#add_inputName").parent().parent().addClass("has-error");
	                    $("#helpBlock_add_inputName").text("该账号已存在");
	                    $(".emp_save_btn").attr("btn_name_exists", "error");
	                }
	            }
	        });
	    });
	  
	  //邮箱验证
	  $("#add_inputEmail").change(function(){
	    	console.log("邮箱验证");
	    	var inputEmail = $("#add_inputEmail").val();
	    	var regEmail = /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/;
	    	  if (!regEmail.test(inputEmail)){
	              //输入框变红
	              $("#add_inputEmail").parent().parent().addClass("has-error");
	              //输入框下面显示红色提示信息
	              $("#helpBlock_add_inputEmail").text("输入邮箱格式不正确！");
	              return false;
	          }else {
	              //移除格式
	              $("#add_inputEmail").parent().parent().removeClass("has-error");
	              $("#add_inputName").parent().parent().addClass("has-success");
	              $("#helpBlock_add_inputEmail").hide();
	          }

	    });

	  //确定按钮
	         
        $("#save").click(function(){
        	console.log($(".add_emp_form").serialize());
            $.ajax({
                url:"/HRMS/user/addemp",
                type:"POST",
                data:$(".add_emp_form").serialize(),
                success:function (result) {
                    if (result.code == 100){
                        alert("员工新增成功");
                        $('#emp-add-modal').modal("hide");
       window.location.href="${pageContext.request.contextPath}/user/emmpage.html";
                        //跳往最后一页，由于新增记录，所以要重新查询总页数
                       
                    } else {
                        alert("员工新增失败！");
                    }
                }

            });
        })


})
</script>

</body>
</html>
